package com.example;

import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

//@Configuration
public class HeaderConfig {

    @Bean
    @ConditionalOnClass(name = "com.itheima.service.ServiceA") // 检查环境(JVM环境)中是否存在ServiceA的字节码, 有就创建该Bean对象,交给IOC容器管理
    public HeaderParser headerParser() {
        return new HeaderParser();
    }

    @Bean
    @ConditionalOnMissingBean
    // 检查环境中是否存在指定的bean(不存在才进行声明), 可以在()指定, 没有就是默认的返回值的Bean, 不指定名字就是当前被修饰的bean-->headerGenerator
    public HeaderGenerator headerGenerator() {
        return new HeaderGenerator();
    }


    @Bean
    @ConditionalOnProperty(name = "name", havingValue = "itheima") // 配置环境->检查环境中是否存在指定的属性和值
    public TokenParser tokenParser() {
        return new TokenParser();
    }
}
